package edu.suse.service.impl;

import edu.suse.common.base.RespResult;
import edu.suse.entity.SysDept;
import edu.suse.mapper.SysDeptMapper;
import edu.suse.service.SysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SysDeptServiceImpl implements SysDeptService {

    @Resource
    private SysDeptMapper sysDeptMapper;


    @Override
    public RespResult selectAll(Integer page, Integer pageSize) {
//        System.out.println(sysDeptMapper.selectAll(page,pageSize));
        List<SysDept> sysDeptList = sysDeptMapper.selectAll(page,pageSize);
//        log.info("collect:{}",sysDeptMapper.selectAll(page,pageSize));
        return RespResult.success(sysDeptList);
    }

    @Override
    public int loadPage() {
        log.info("页码:{}",sysDeptMapper.loadPage());
        return sysDeptMapper.loadPage();
    }

    @Override
    public RespResult findSysDeptAll() {
        List<SysDept> sysDeptList = sysDeptMapper.querySysDeptList();
        return RespResult.success(sysDeptList);
    }

    @Override
    public RespResult insertSysDept(SysDept sd) {
        SysDept sysDept = sysDeptMapper.insertSysDept(sd);
        return RespResult.success(sysDept);
    }

    @Override
    public RespResult updateSysDept(String title, int sort, String remark, int status, int id) {
        SysDept sysDept = sysDeptMapper.updateSysDept(title,sort,remark,status,id);
        return RespResult.success(sysDept);
    }

    @Override
    public RespResult findOneSysDept(int id) {
        SysDept sysDept = sysDeptMapper.findOneSysDept(id);
        System.out.println(sysDept.getUpdateBy());
        return RespResult.success(sysDept);
    }

    @Override
    public RespResult deleteSysDept(int id) {
        sysDeptMapper.deleteSysDept(id);
        return RespResult.success("删除成功！");
    }
}
